package com.pactera.demo.common.dto;

import com.pactera.demo.common.enums.StatusCodeEnum;
import com.sun.istack.internal.NotNull;
import lombok.Data;

/**
 * <p>
 * 通用返回结果，用于Controller所有rest方法的返回值
 * </p>
 *
 * @author chang.zhou
 * @version 1.0
 * @date Created in 2020/2/13 15:25
 */
@Data
public class ResponseResult {

    private boolean success;
    private int code;
    private String message;
    private Object data;

    public ResponseResult(boolean success, @NotNull StatusCodeEnum status, String message, Object data) {
        this.success = success;
        this.code = status.getCode();
        this.message = message == null ? status.getMessage() : message;
        this.data = data;
    }

    public static ResponseResult success(){
        return new ResponseResult(true, StatusCodeEnum.OK,null,null);
    }

    public static ResponseResult success(Object data){
        return new ResponseResult(true, StatusCodeEnum.OK,null,data);
    }

    public static ResponseResult success(Object data, String message){
        return new ResponseResult(true, StatusCodeEnum.OK,message,data);
    }

    public static ResponseResult fail(StatusCodeEnum status, String message, Object data){
        return new ResponseResult(false,status,message,data);
    }

    public static ResponseResult fail(StatusCodeEnum status){
        return new ResponseResult(false,status,status.getMessage(),null);
    }

    public static ResponseResult fail(StatusCodeEnum status, Object data){
        return new ResponseResult(false,status,status.getMessage(),data);
    }

}
